<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<script type="text/javascript">
	$('#admin_yhgl_datagrid').datagrid({
		url : '${pageContext.request.contextPath}/userAction!datagrid.action',
		fit:true,
		border:false,
		pagination:true,
		idField:'id',
		fitColumns:true,
		//rownumbers:true,不建议使用
		sortName:'name',
		sortOrder:'asc',
		checkOnSelect:true,
		selectOnCheck:true,
		pageSize:5,
		pageList:[5,6,10,20,30,],
		columns : [ [ {
			field : 'id',
			title : '编号', 
			width : 150,
			checkbox:true
		}, {
			field : 'name',
			title : '登录名称',
			width : 150,
			sortable:true
		}, {
			field : 'password',
			title : '密码',
			width : 150,
			formatter:function(value,row,index){
				return'******';//<span title="'+row.name+' '+value+'">'+value+'</span>
			}
		}, {
			field : 'createdatetime',
			title : '创建时间',
			width : 150,
			sortable:true
		},{
			field : 'modifydatetime',
			title : '最后修改时间',
			width : 150,
			sortable:true
		}] ],
		toolbar:[{
			text:'增加',
			iconCls:'icon-add',
			handler:function(){
				addpend();
			}
		},'-',{
			text:'删除',
			iconCls:'icon-remove',
			handler:function(){
				remove();
			}
		},'-',{
			text:'修改',
			iconCls:'icon-edit',
			handler:function(){
				eidtFun();
			}
		}]
	}); 	
	function searchFun(){
		$('#admin_yhgl_datagrid').datagrid('load',{
			name:$('#admin_yhgl_layout input[name=name]').val()
		});
	}
	function clearFun(){
		$('#admin_yhgl_layout input[name=name]').val('');
		$('#admin_yhgl_datagrid').datagrid('load',{});
	}
	function addpend(){
		$('#admin_yhgl_addForm input').val('');
		$('#admin_yhgl_addDialog').dialog('open');
	}
	function remove(){
		var rows=$('#admin_yhgl_datagrid').datagrid('getChecked');
		var ids= [];
		if(rows.length>0){
		  $.messager.confirm('确认','您是否要确认删除当前选中的项目？',function(r){
		   	if(r){
					for(var i=0;i<rows.length;i++){
						ids.push(rows[i].id);
					}
					$.ajax({
						url:'${pageContext.request.contextPath}/userAction!remove.action',
						data:{
							ids:ids.join(',')
						},
						dataType:'json',
						success:function(d){
							$('#admin_yhgl_datagrid').datagrid('load');
							$('#admin_yhgl_datagrid').datagrid('unselectAll');
							$.messager.show({
								title:'提示',
								msg:d.msg
							});
						}
					});
				}
		  });
		}else{
			$.messager.show({
				title:'提示',
				msg:'请选中要删除的行'
			});
		}
	}
	function eidtFun(){
		var rows=$('#admin_yhgl_datagrid').datagrid('getChecked');
	  if(rows.length==1){
	   var d= $('<div/>').dialog({
			width:530,
			height:170,
			href:'${pageContext.request.contextPath}/admin/yhglEdit.jsp',
			modal:true,
			title:'编辑用户',
			buttons:[{
				text:'编辑',
				handler:function(){
					$('#admin_yhglEdit_form').form('submit',{
						 url:'${pageContext.request.contextPath}/userAction!edit.action',
						 success:function(r){
							var obj= jQuery.parseJSON(r);
					    	if(obj.success){
							 d.dialog('close');
							 $('#admin_yhgl_datagrid').datagrid('updateRow',{
							 	index:$('#admin_yhgl_datagrid').datagrid('getRowIndex',rows[0]),
							 	row:obj.obj							 		
							 });
							 $.messager.show({
								title:'提示',
								msg:obj.msg
							 });
							}
						}
					});
				}
			}],
			onClose:function(){
				$(this).dialog('destroy');
			},
			onLoad:function(){
			//	$('#admin_yhglEdit_form input[name=id]').val(rows[0].id);
			//$('#admin_yhglEdit_form input[name=name]').val(rows[0].name);
			$('#admin_yhglEdit_form').form('load',rows[0]);
			}
		});
	}else{
		$.messager.alert("提示","请选择您要编辑的行！");
	}
 }
</script>
<div id="admin_yhgl_layout" class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'north',border:false,title:'查询条件'" style="height:70px;">
			<input name="name"/>
		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="searchFun()">查询</a>
		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true" onclick="clearFun()">清空</a>
	</div>
	<div data-options="region:'center',border:false">
		<table id="admin_yhgl_datagrid"></table>
	</div>
</div>
    <div id="admin_yhgl_addDialog" class="easyui-dialog" title="添加用户" style="width:520px;height:170px;"  
            data-options="iconCls:'icon-save',closed:true,modal:true,buttons:[{
				text:'增加',
				iconCls:'icon-add',
				handler:function(){
				    $('#admin_yhgl_addForm').form('submit', {  
				      		url:'${pageContext.request.contextPath}/userAction!add.action',
				      		success: function(r){  
				      		var obj=jQuery.parseJSON(r);
				      		if(obj.success){
				      			/*$('#admin_yhgl_datagrid').datagrid(' appendRow',obj.obj);*/
				      			$('#admin_yhgl_datagrid').datagrid('insertRow',{
				      				index:0,
				      				row:obj.obj
				      			});
				      			$('#admin_yhgl_addDialog').dialog('close');
				      		}
				      		$.messager.show({
				      			title:'提示',
				      			msg:obj.msg
				      		});
				        }  
				    });  
				}
			}]">  
       <form id="admin_yhgl_addForm" method="post">
	<table>
		<tr>
			<th>编号</th>
			<th><input name="id" readonly="readonly"/></th>
			<th>登录名称</th>
			<td><input name="name" class="easyui-validatebox" data-options="required:true"/></td>
		</tr>
		<tr>
			<th>密码</th>
			<th><input name="password" type="password" class="easyui-validatebox" data-options="required:true"/>
			<th>创建时间</th>
			<td><input name="createdatetime" readonly="readonly"/></td>
		</tr>
		<tr>
			<th>最后修改时间</th>
			<td><input name="modifydatetime" readonly="readonly"/></td>
			<th>性別</th>
			<td>
			<select id="cc" class="easyui-combobox" name="gender" style="width:100px;"data-options="required:true">
				<option value="男" selected="selected">男</option>
				<option value="女">女</option>
			</select>
			</td>
		</tr>
	</table>
	</form>
    </div>  
    